package main

import (
	"fmt"

	jpushclient "github.com/ylywyn/jpush-api-go-client"
)

const (
	appKey = "8c3c69a086cf7cbf48dfda4e"
	secret = "f3b696745567eccf293cb596"
)

func main() {
	// Platform
	var pf jpushclient.Platform
	pf.Add(jpushclient.ANDROID)
	pf.Add(jpushclient.IOS)
	pf.Add(jpushclient.WINPHONE)

	// 发送给所有人
	// Audience
	// var ad jpushclient.Audience
	// ad.All() // 设置推送目标为所有用户

	// 这里可以设置成需要推送的用户
	// Audience
	// var ad jpushclient.Audience
	// ids := []string{"id1", "id2"} // 替换为你的用户ID
	// ad.SetID(ids) // 设置推送目标为指定的用户ID
	// Audience
	var ad jpushclient.Audience
	regIDs := []string{"your_reg_id_1", "your_reg_id_2"} // 替换为具体的RegID
	ad.SetID(regIDs)

	// Notice
	var notice jpushclient.Notice
	notice.SetAlert("alert_test")
	notice.SetAndroidNotice(&jpushclient.AndroidNotice{Alert: "AndroidNotice"})
	notice.SetIOSNotice(&jpushclient.IOSNotice{Alert: "IOSNotice"})
	notice.SetWinPhoneNotice(&jpushclient.WinPhoneNotice{Alert: "WinPhoneNotice"})

	// Message
	var msg jpushclient.Message
	msg.Title = "Hello"
	msg.Content = "你是ylywn"

	// Payload
	payload := jpushclient.NewPushPayLoad()
	payload.SetPlatform(&pf)
	payload.SetAudience(&ad)
	payload.SetMessage(&msg)
	payload.SetNotice(&notice)

	// Convert Payload to Bytes
	bytes, _ := payload.ToBytes()
	fmt.Printf("%s\r\n", string(bytes))

	// Push
	c := jpushclient.NewPushClient(secret, appKey)
	str, err := c.Send(bytes)
	if err != nil {
		fmt.Printf("err:%s", err.Error())
	} else {
		fmt.Printf("ok:%s", str)
	}
}
